package com.grm.demo.cyclicbarrier;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CyclicBarrier;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        CyclicBarrier barrier = new CyclicBarrier(3);

        List<Thread> threads = new ArrayList<>(3);
        threads.add(new Thread(new MyCyclicBarrier(barrier, "张三")));
        threads.add(new Thread(new MyCyclicBarrier(barrier, "李四")));
        threads.add(new Thread(new MyCyclicBarrier(barrier, "王五")));

        for (Thread thread : threads) {
            thread.start();
        }

        //等待所有线程跑完
        for (Thread thread : threads) {
            thread.join();
        }
    }
}
